import rxAjax from '@/assets/js/ajax.js';
import {Util} from "@lowcode/jpaas-common-lib";
import InsPortalDefApi from "../../portal/core/insPortalDef";
import FormPcApi from "./formPc";
import FormPermissionEdit from '@/views/modules/form/core/FormPermissionEdit';

//表单权限配置 api接口
export const FormPermissionApi = {};

FormPermissionApi.baseUrl= '/api-form/form/core/formPermission';
FormPermissionApi.exportUrl= FormPermissionApi.baseUrl + '/listExport';

/**
 * 表单权限设置
 * @param pkId
 * @returns {*}
 */
FormPermissionApi.permissionSeting=function(self_,solutionId,type,boDefId) {
  var conf = {
    component: FormPermissionEdit,
    title: self_.i18n('list.permisDesign','表单权限设计'),
    widthHeight: ['1050px', '600px']
  };
  var baseConf = {
    curVm: self_,
    data: {
      pkId: solutionId,
      saveType:type,
      boDefId:boDefId,
      callback: function(data) {
      }
    }
  };
  let config = Object.assign(baseConf, conf);
  Util.open(config,function(action) {
  });
}


//查询列表
FormPermissionApi.query=function (parameter) {
  var url= FormPermissionApi.formPermission + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

/**
* 获取单记录
* @param pkId
* @returns {*}
*/
FormPermissionApi.get =function(type,pkId) {
  var url= FormPermissionApi.baseUrl + '/getByFormSolutionId?pkId=' + pkId+"&type="+type;
  return rxAjax.get(url);
}


//保存数据
FormPermissionApi.save =function(parameter) {
  var url= FormPermissionApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}


//删除数据
FormPermissionApi.del =function(parameter) {
  var url= FormPermissionApi.formPermission + '/del';
  return rxAjax.postUrl(url,parameter);
}

//获取权限设置策略列表
FormPermissionApi.getPermissionList =function() {
  var url= FormPermissionApi.baseUrl + '/getPermissionList';
  return rxAjax.get(url);
}

/**
 * 重新加载表单方案权限
 * @param solutionId
 * @returns {*}
 */
FormPermissionApi.reloadFormPermission =function(formId) {
    var url= FormPermissionApi.baseUrl + '/reloadFormPermission?solutionId='+formId;
    return rxAjax.get(url);
}

export  default FormPermissionApi;

